/*
day142_2
2020.1.17
*/ 
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;


class Solution1 {
public:
    int findLHS(vector<int>& nums) 
	{
        unordered_map<int,int> m;
        for(int i=0;i<nums.size();i++)
        {
        	++m[nums[i]];
		}
		
		int res=0;
		for(int i=0;i<nums.size();i++)
		{
			if(m[nums[i]+1])
			{
				int tem = m[nums[i]] + m[nums[i]+1];
				res = tem > res ? tem : res;
			} 
			
		}
		
		return res;
    }
};




class Solution2 {
public:
    int findLHS(vector<int>& nums) 
	{
    	unordered_map<int,int> m;
    	int res=0;
    	
		for(int i=0;i<nums.size();i++)
		{
			m[nums[i]]++;
			int a=m[nums[i]]+m[nums[i]-1];
			int b=m[nums[i]]+m[nums[i]+1];
			
			if(m[nums[i]-1])	res=res>a ? res : a;
			if(m[nums[i]+1])	res=res>b ? res : b;
		} 
		
		return res;
    }
};

int main()
{
	return 0;
}
